#include <bits/stdc++.h>
using namespace std;
struct cars
{
	int d;
	int v;
	int a;
	double f;
	double t;
	int pos;
};
cars x[100001];
int p[100001],s[1000001];
bool cmp(cars a,cars b)
{
	return a.f<b.f;
}
int main()
{
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int T;
	cin>>T;
	while(T--)
	{
		int n,m,L,V,ans1=0,ans2=0;
		cin>>n>>m>>L>>V;
		for(int i=1;i<=L;i++)
			s[i]=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d%d",&x[i].d,&x[i].v,&x[i].a);
			if(x[i].v>V&&x[i].a>=0)
			{
				x[i].f=double(x[i].d);
				x[i].t=double(L);
			}
			else if(x[i].v>V&&x[i].a<0)
			{
				x[i].f=double(x[i].d);
				double dis=double(V*V-x[i].v*x[i].v)/2.0/double(x[i].a);
				x[i].t=min(double(L),x[i].f+dis-(1e-6));
			}
			else if(x[i].v==V&&x[i].a>0)
			{
				x[i].f=double(x[i].d)+(1e-6);
				x[i].t=double(L);
			}
			else if(x[i].v<V&&x[i].a>0)
			{
				double dis=double(V*V-x[i].v*x[i].v)/2.0/double(x[i].a);
				if(x[i].d+dis+(1e-6)>double(L))
				{
					x[i].f=-1;
					x[i].t=-1;
				}
				else
				{
					x[i].f=x[i].d+dis+(1e-6);
					x[i].t=double(L);
				}
			}
			else 
			{
				x[i].f=-1;
				x[i].t=-1;
			}
		}
		sort(x+1,x+n+1,cmp);
		int w=0;
		for(int i=1;i<=m;i++)
		{
			scanf("%d",&p[i]);
			s[p[i]]++;
		}
		for(int i=1;i<=L;i++)
			s[i]+=s[i-1];
		for(int i=1;i<=n;i++)
		{
			if(x[i].f==-1)
				continue;
			if(s[int(x[i].t+1e-8)]-s[int(x[i].f+-1e-8)]>0)
				ans1++;
			else
				x[i].f=-1;
		}
		for(int i=1;i<=n;i++)
		{
			if(x[i].f==-1)
				continue;
			int l=1,r=m;
			while(l<=r)
			{
				int mid=(l+r)/2;
				if(x[i].t<double(p[mid]))
					r=mid-1;
				else
					l=mid+1;
			}
			x[i].pos=r;
		}
		for(int i=1;i<=n;i++)
		{
			if(x[i].f==-1)
				continue;
		//	cout<<i<<' '<<w<<' ';
		//	printf("%f %f\n",x[i].f,x[i].t);
			if(x[i].f>double(p[w]))
			{
				ans2++;
				w=x[i].pos;
				/*while(x[i].f>double(p[w]))
					w++;
				while(w<m&&double(p[w+1])<=x[i].t)
					w++;*/
			}
			else if(double(p[w])>x[i].t)
			{
				w=x[i].pos;
				/*
				while(double(p[w])>x[i].t)
					w--;*/
			}
			
		}
		cout<<ans1<<' '<<m-ans2<<endl;
	}
	return 0;
}

